import { getCurrentInstance } from "vue";
import { useRouter } from 'vue-router'
import { ApiRegister } from '@/apis/user'
interface RegisterParm {
    username: string,
    password: string,
    password2: string,
    realName: string,
    phone: string,
}
//表单验证
export function useRegister(registerModel: RegisterParm) {
    const { proxy } = getCurrentInstance() as any;
    const router = useRouter();
    const register = async () => {
        proxy.$refs.registerFormRef.validate(async (valid: boolean) => {
            if (valid) {
                if ((registerModel.password === registerModel.password2)) {//把这里改成两个密码框相等
                    // 调用发请求函数
                    const flag = await ApiRegister(registerModel)
                    // toRegister();
                    if (flag) {
                        setTimeout(() => {
                            router.push({ path: 'login' })
                        }, 1000);
                    }
                }
            }
        })
    }
    return {
        register
    }
}
// //发axios
// export function toRegister(){

// }
